package com.luobo.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {

    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //分组名称
                .groupName("大地保险")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.luobo.yfh"))
                .paths(PathSelectors.any())
                .build()
          //      .globalOperationParameters(parameters)
                //  .securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey())
                ;

    }


//    @Bean(value = "defaultApi1")
//    public Docket defaultApi1() {
//        List<Parameter> parameters = Lists.newArrayList();
//        ParameterBuilder parameterBuilder = new ParameterBuilder();
//        parameterBuilder.name("token")
//                .description("token令牌")
//                .modelRef(new ModelRef("String"))
//                .parameterType("header")
//                .required(true)
//                .build();
//        parameters.add(parameterBuilder.build());
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                //分组名称
//                .groupName("订单服务")
//                .select()
//                //这里指定Controller扫描包路径
//                .apis(RequestHandlerSelectors.basePackage("com.luobo"))
//                .paths(PathSelectors.any())
//                .build()
//                .globalOperationParameters(parameters)
//                //  .securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey())
//                ;
//
//    }


    private ApiInfo apiInfo() {

        List<VendorExtension> list = new ArrayList<VendorExtension>();
        list.add(new StringVendorExtension("name", "安稳"));

        Contact contact = new Contact("胡安稳 anwen375@qq.com", "", "anwen375@qq.com");


        return new ApiInfo(
                "中国投标保函网标准版接口文档",
                "中国投标保函网 面向保险机构关于投标保函系统对接接口的文档",
                "3.0.0",
                "https://www.api.zgtbbhw.com/ywzxapi/",
                contact,
                "",
                "",
                list);
    }
}